home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2010-01-05 | 47.6 KB | 1,530 lines
var bpriv = { prompts: Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService), wm: Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator), prefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.bprivacy."), mw: window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIWebNavigation) .QueryInterface(Components.interfaces.nsIDocShellTreeItem) .rootTreeItem .QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIDOMWindow), nsIFilePicker: Components.interfaces.nsIFilePicker, lsos: [], Stack: [], timerID: 0, tStart: null, tTicks: null, selected: null, Scan: 0, LOG: function(text) { var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); consoleService.logStringMessage(text); }, WindowOnEnter: function(event) { if (event.keyCode == 13) { return false; } return true; }, openHelp: function() { if(gBrowser) gBrowser.selectedTab = gBrowser.addTab('chrome://bp/content/bphelp.html'); }, getDoc: function() { var doc = bpriv.mw.document; if(!doc) doc = window.document; return doc; }, convert: function() { var PrefSrv = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); //AutoDelLSO try{ //if( !navigator.preference("extensions.bprivacy.version") || parseInt(navigator.preference("extensions.bprivacy.version")) < 139) if(navigator.preference("extensions.bprivacy.AutoDelLSO") == false) navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode", 1); PrefSrv.clearUserPref("extensions.bprivacy.AutoDelLSO"); //delete preference }catch(e){} //FlashAppDir try{ if(navigator.preference("extensions.bprivacy.flashAppDir") && String(navigator.preference("extensions.bprivacy.flashAppDir")).length) { var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); Dir.initWithPath(navigator.preference("extensions.bprivacy.flashAppDir")); if(Dir.path && Dir.exists() && Dir.isDirectory()) bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, Dir); } PrefSrv.clearUserPref("extensions.bprivacy.flashAppDir"); //delete preference }catch(e){} //DOMStorage try{ if(navigator.preference("extensions.bprivacy.domstorage.allowed") == false ) { navigator.preference("extensions.bprivacy.domclear", true); navigator.preference("dom.storage.enabled", true); PrefSrv.clearUserPref("extensions.bprivacy.domstorage.allowed"); //delete preference } }catch(e){} }, //startup of FireFox firstload: function(event) { //debug //navigator.preference("javascript.options.showInConsole", true); bpriv.convert(); if(!navigator.preference("extensions.bprivacy.initiated")) { navigator.preference("extensions.bprivacy.initiated", true); navigator.preference("browser.send_pings", false); navigator.preference("extensions.bprivacy.sendpings.allowed", false); bpriv.GetFlashDir(2);//set flashApp directory preference, scan if necessary setTimeout("bpriv.openHelp()", 25000); }else { if(navigator.preference("extensions.bprivacy.alwaysReScan") || !bpriv.GetFlashDir(0)) bpriv.GetFlashDir(1); } if( ( !navigator.preference("extensions.bprivacy.sendpings.allowed") && (navigator.preference("extensions.bprivacy.sendpings.allowed") != navigator.preference("browser.send_pings")) ) ) { if(confirm("BetterPrivacy:\r\nThe extension detected that one or more privacy settings have been modified!\r\nPress OK to correct those values.")){ navigator.preference("browser.send_pings", navigator.preference("extensions.bprivacy.sendpings.allowed")); } } if(navigator.preference("extensions.bprivacy.DelTimerInterval") < 1) navigator.preference("extensions.bprivacy.DelTimerInterval", 1); if(window == bpriv.mw) { //// window.addEventListener("unload", bpriv.onexit, false); if(navigator.preference("extensions.bprivacy.domclear")){ bpriv.DelDOM(); }//AutoDelDOM if(navigator.preference("extensions.bprivacy.AutoDelLSOnStart")) bpriv.prepareDelLSO(2, null); bpriv.startDelTimer(); } bpriv.SetKeys(); navigator.preference("extensions.bprivacy.version", String(bpriv.getVersion()).replace(/\./, "")); bpriv.setPropagation(); },//end menue load setPropagation: function() { if(navigator.preference("extensions.bprivacy.propagate")) navigator.preference("general.useragent.extra.betterprivacy", "BetterPrivacy-" + bpriv.getVersion()); else navigator.preference("general.useragent.extra.betterprivacy", ""); }, getVersion: function() { return Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager) .getItemForID("{d40f5e7b-d2cf-4856-b441-cc613eeffbe3}").version; }, SetKeys: function() { var kNode = document.getElementById("key_bp"); if(kNode) { var keyCode = navigator.preference("extensions.bprivacy.keycode"); if(keyCode){ kNode.setAttribute("disabled", false); kNode.setAttribute("modifiers", String(navigator.preference("extensions.bprivacy.keymodifiers"))); kNode.setAttribute("key", String.fromCharCode(keyCode)); } } }, GetDirs: function(currentDir, dirArray) { var entries; try{ entries = currentDir.directoryEntries; }catch(e){} while(entries && entries.hasMoreElements()) { var entry = entries.getNext(); try{ entry.QueryInterface(Components.interfaces.nsIFile); if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry)) { dirArray.push(entry); bpriv.GetDirs(entry, dirArray); } }catch(e){bpriv.LOG("BetterPrivacy: Failure parsing directories - " + e);} } return dirArray; }, DelDirSortAlgo: function(file1, file2) { if (file1.path.length > file2.path.length) return -1; else if (file2.path.length > file1.path.length) return 1; return 0; }, delDirs: function(FlashDirRoot) { if(!FlashDirRoot || !navigator.preference("extensions.bprivacy.delDirs")) return; // Delete ISO8601 formated directories var dirArray = new Array(); bpriv.GetDirs(FlashDirRoot, dirArray); var numDirsToDelete = dirArray.length; dirArray.sort(bpriv.DelDirSortAlgo); for(var i=0; i<numDirsToDelete; i++) { try{ //never delete non-empty directories (FF throws NS_ERROR_FILE_DIR_NOT_EMPTY if remove attribut is false) dirArray[i].remove(false); }catch(e) { if(e.name != "NS_ERROR_FILE_DIR_NOT_EMPTY") bpriv.LOG("BetterPrivacy: Unable to delete directory (usually due to an open handle or missing permission)- " + dirArray[i].path + " - " + e); } } dirArray = null; }, onexit: function(event) { ////try{bpriv.mw.removeEventListener("unload", bpriv.onexit, false);}catch(e){} try{ bpriv.mw.clearTimeout(bpriv.timerID); var enumerator = bpriv.wm.getEnumerator("navigator:browser"); /* if(enumerator && !enumerator.hasMoreElements()){ //is it not the last window? if(navigator.preference("extensions.bprivacy.domclear")){ bpriv.DelDOM(); }//AutoDelDOM bpriv.prepareDelLSO(3, null); } */ var wincount = 0; while(enumerator && enumerator.hasMoreElements()){ wincount++; enumerator.getNext(); } if(wincount == 1){ if(navigator.preference("extensions.bprivacy.domclear")){ bpriv.DelDOM(); }//AutoDelDOM bpriv.prepareDelLSO(3, null); } }catch(e){alert("BetterPrivacy\r\nError on exit\r\nPlease report this to the author " + e);} //When a string is assigned to the returnValue property of window.event, a dialog box appears.... //the problem seems to be: //1. when onbeforeunload is called, it will take the return value of the handler as window.event.returnValue. //2. it will then parse the return value as a string (unless it is null) //3. since false is parsed as a string, the dialogue box will fire, which will then pass an appropriate true/false //the result is, there doesn't seem to be a way of assigning false to onbeforeunload, to prevent it from the default dialogue. // return true; }, DelDOM: function() { var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile); file.append("webappsstore.sqlite"); if(file.exists()) // if it exists, delete { try{ file.remove(false); }catch(e){ bpriv.LOG("BetterPrivacy: Deletion of DOM data currently impossible due to open handle - trying again later."); } } }, checkFlashFolder: function() { if (!bpriv.GetFlashDir(0)) { if (!navigator.preference("extensions.bprivacy.donotaskforfolder")) { check = {value: false}; var confirmed = bpriv.prompts.confirmCheck(window, "BetterPrivacy", bpriv.getString("askfornewpath"), bpriv.getString("askfornewpath2"), check); navigator.preference("extensions.bprivacy.donotaskforfolder", check.value); if(confirmed) window.openDialog('chrome://bp/content/bp.xul', '_blank', 'chrome=yes, modal=yes, resizable=yes, centerscreen=yes'); } } return bpriv.GetFlashDir(0); }, LSOtoDelete: function() { bpriv.lsos = []; if(!bpriv.checkFlashFolder()) return 0; bpriv.LoadLsos(bpriv.GetFlashDir(0), true); var deleted = 0; for (var x=0;x<bpriv.lsos.length;x++)//first check number of LSO's to be deleted { try{ var defaultCookie = false; var protectedCookie = false; if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0) protectedCookie = true; var dir = String(bpriv.lsos[x].path).replace(/settings\.sol/, ""); var regex = new RegExp(navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i'); if( bpriv.lsos[x].file.leafName.toLowerCase() == navigator.preference("extensions.bprivacy.DefaultLSOName") && dir.match(regex)) defaultCookie = true; if(!protectedCookie && (!defaultCookie || navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion"))) deleted++; }catch(e){bpriv.LOG("BetterPrivacy: Error while counting LSOs");} } return deleted; }, prepareDelLSO: function(mode, trange) //mode 1=byTimer 2=onStartup 3=onExit { try{ if(mode == 3) { if(navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode") == 0) { if(!navigator.preference("extensions.bprivacy.donotaskonexit")) { window.openDialog("chrome://bp/content/progress.xul", "_blank", "chrome=yes, modal=yes, resizable=no, centerscreen=yes, alwaysRaised=yes", mode); }else { if(bpriv.LSOtoDelete()) bpriv.DelLSO(mode, trange); } } else if(navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode") == 1) { if(!navigator.preference("privacy.item.extensions-betterprivacy")) return; if(bpriv.LSOtoDelete()) bpriv.DelLSO(mode, trange); } }else { if(bpriv.LSOtoDelete()) bpriv.DelLSO(mode, trange); } }catch(e){alert("BetterPrivacy: Error in prepare delete LSO function: " + e);} }, processProgressWindow: function(win, mode) //always mode 3 { var deleted = bpriv.LSOtoDelete(); //win.close(); if(deleted) { check = {value: false}; var delconfirmed = bpriv.prompts.confirmCheck(window, bpriv.getString("askfordeletion1"), bpriv.getString("askfordeletion2") + " " + deleted + " " + bpriv.getString("askfordeletion3"), bpriv.getString("askfordeletion4"), check); navigator.preference("extensions.bprivacy.donotaskonexit", check.value); if(delconfirmed) bpriv.DelLSO(mode, null); } win.close();//keep open until here, else the processing might be aborted before finishing }, DelLSO: function(mode, range)//mode 0=ClearHistory 1=byTimer 2=onStartup 3=onExit { try{ deleted = 0; for (var x=0;x<bpriv.lsos.length;x++)//effectively delete LSO's { try{ var defaultCookie = false; var protectedCookie = false; if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0) protectedCookie = true; var dir = String(bpriv.lsos[x].path).replace(/settings\.sol/, ""); var regex = new RegExp(navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i'); if( bpriv.lsos[x].file.leafName.toLowerCase() == navigator.preference("extensions.bprivacy.DefaultLSOName") && dir.match(regex)) defaultCookie = true; if(!protectedCookie && (!defaultCookie || navigator.preference("extensions.bprivacy.DefaultFlashCookieDeletion"))) { var cDate = new Date(); if( mode == 1 && navigator.preference("extensions.bprivacy.useDelTimerDelay") && cDate.getTime() >= bpriv.lsos[x].file.lastModifiedTime && cDate.getTime()-bpriv.lsos[x].file.lastModifiedTime < navigator.preference("extensions.bprivacy.DelTimerInterval") * 1000 ) continue; if( mode == 0 && range && cDate.getTime() >= bpriv.lsos[x].file.lastModifiedTime && cDate.getTime()-bpriv.lsos[x].file.lastModifiedTime > range ) continue; bpriv.lsos[x].file.remove(false); deleted++; } }catch(e){bpriv.LOG("BetterPrivacy: Error while deleting LSO");} } navigator.preference("extensions.bprivacy.removed", navigator.preference("extensions.bprivacy.removed") + deleted);//statistics navigator.preference("extensions.bprivacy.removedSession", navigator.preference("extensions.bprivacy.removedSession") + deleted);//statistics bpriv.delDirs(bpriv.GetFlashDir(0)); //remove folders bpriv.updateKnownLSOs(); }catch(e){alert("BetterPrivacy: Error in delete LSO function: " + e);} }, updateKnownLSOs: function() { if(bpriv.lsos) navigator.preference("extensions.bprivacy.LSOcount", bpriv.lsos.length); }, modifiedSince: function(lso) { var c = new Date(); //will hold current ticks var m = new Date(); m.setTime(parseInt(lso.modified)); //modified lso ticks var diff = c.getTime() - m.getTime(); return diff; }, startDelTimer: function() { bpriv.tStart = new Date(); bpriv.updateDelTimer(true); }, stopDelTimer: function() { if(bpriv.timerID) { clearTimeout(bpriv.timerID); bpriv.timerID = 0; } bpriv.tStart = null; }, updateDelTimer: function(initiated) { if (FlashDirRoot = bpriv.GetFlashDir(0)) { if(navigator.preference("extensions.bprivacy.NotifyOnNewLSO")) { bpriv.lsos = []; bpriv.LoadLsos(FlashDirRoot, false); if(!initiated && navigator.preference("extensions.bprivacy.NotifyOnNewLSO") == 1 && bpriv.lsos.length > navigator.preference("extensions.bprivacy.LSOcount")) { var count = bpriv.lsos.length - navigator.preference("extensions.bprivacy.LSOcount"); var str = count > 1 ? " LSO's have" : " LSO has"; var message = "BetterPrivacy detected that " + count + str + " been placed on your harddisk!"; bpriv.NotifyNewLSO(bpriv.hashString(message), message); }else navigator.preference("extensions.bprivacy.NotifyOnNewLSO", 1); bpriv.updateKnownLSOs(); } } if(bpriv.timerID) clearTimeout(bpriv.timerID); if(!bpriv.tStart) bpriv.tStart = new Date(); var tDate = new Date(); tDate.setTime(tDate.getTime() - bpriv.tStart.getTime()); if(tDate.getTime() / (navigator.preference("extensions.bprivacy.DelTimerInterval") * 1000) >= 1){ if(navigator.preference("extensions.bprivacy.useDelTimer")) bpriv.prepareDelLSO(1, null); bpriv.tStart = null; } bpriv.timerID = setTimeout("bpriv.updateDelTimer()", 1000); }, sortMultiDimensional: function (a,b) { // this sorts the array using the second element return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0)); }, NotifyNewLSO: function(value, message) { var c = new Date(); var mins = c.getMinutes(); if(mins < 10) mins = "0" + mins; var secs = c.getSeconds(); if(secs < 10) secs = "0" + secs; var ModifiedLSOs = " Timestamp: " + c.getHours() + ":" + mins + ":" + secs; var count = 0; for (var x=0;x<bpriv.lsos.length;x++) { if(bpriv.modifiedSince(bpriv.lsos[x]) < 2000) { if(!count) ModifiedLSOs += ' Last modified:'; ModifiedLSOs += ' "' + bpriv.lsos[x].file.leafName + '"'; count++; } } bpriv.Notification(value, message + ModifiedLSOs); }, Notification: function(value, message) { var buttons = [{ label: "View LSOs", callback: function() { bpriv.RemoveNotification(value); bpriv.showBetterPrivacy(); }, accessKey: null, popup: null }]; var nbox = window.getBrowser().getNotificationBox(); nbox.appendNotification(message, value, "chrome://bp/content/pie.png", navigator.preference("extensions.bprivacy.NotifyPriority"), buttons); if(navigator.preference("extensions.bprivacy.NotifyDuration")) setTimeout(function(){bpriv.RemoveNotification(value)}, navigator.preference("extensions.bprivacy.NotifyDuration") * 1000, value); }, RemoveNotification: function(value) { if(item = window.getBrowser().getNotificationBox().getNotificationWithValue(value)) window.getBrowser().getNotificationBox().removeNotification(item); }, changeAppDir: function(event) { bpriv.Scan = -1; if (event) { if (event.keyCode != 13) return; var newpath = bpriv.getDoc().getElementById("appdir").value; // if (newpath == navigator.preference("extensions.bprivacy.flashAppDir")) var oldDir; try{ oldDir = bpriv.prefs.getComplexValue("DataDir", Components.interfaces.nsILocalFile); }catch(e){} if (oldDir && newpath == oldDir.path) return; if(!confirm("You changed the FlashApplication folder to: \r\n" + newpath + "\r\nDo you want to apply this modification?")) { if (oldDir) newpath = oldDir.path; else newpath = ""; bpriv.getDoc().getElementById("appdir").value = newpath; } var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); try{ Dir.initWithPath(newpath); newpath = Dir; if(!Dir.path || !Dir.exists() || !Dir.isDirectory()) newpath = null; }catch(e){newpath = null;} }else { var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(bpriv.nsIFilePicker); fp.init(window, bpriv.getString("selectDirTitle"), bpriv.nsIFilePicker.modeGetFolder); var rv = fp.show(); if ((rv != bpriv.nsIFilePicker.returnOK) && (rv != bpriv.nsIFilePicker.returnReplace)) return; var newpath = fp.file; } if(newpath) // navigator.preference("extensions.bprivacy.DataDir", newpath); bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, newpath); bpriv.LSOTreeShow(newpath); return true; }, searchDir: function() { if(bpriv.getDoc().getElementById("searchFolderID").label != bpriv.getString("abort")){ if(FlashDir = bpriv.GetFlashDir(2)) bpriv.LSOTreeShow(FlashDir); }else{ bpriv.Scan = -1; } }, treeView: { treeBox: null, selection: null, get rowCount() { return bpriv.lsos.length; }, setTree: function(treeBox) { this.treeBox = treeBox; }, isSeparator: function(idx) { return false; }, isSorted: function() { return false; }, isEditable: function(idx, column) { return false; }, getCellProperties: function(idx, column, prop) {}, getColumnProperties: function(column, element, prop) {}, getRowProperties: function(row, element, prop) {}, getImageSrc: function() {return null;}, isContainer: function() {return false;}, cycleHeader: function() {}, getCellText: function(idx, column) { if(!bpriv.lsos.length) return ""; //else if (column.id=="folder") else if (column.id=="ident") return bpriv.lsos[idx].ident; else if (column.id=="name") return bpriv.lsos[idx].file.leafName; else if (column.id=="size") return bpriv.lsos[idx].size; else if (column.id=="modified") { var cDate = new Date(); cDate.setTime(parseInt(bpriv.lsos[idx].modified)); return cDate.toLocaleString(); } else if (column.id=="prot") { if(bpriv.lsos[idx].prot.indexOf("d") < 0 && bpriv.lsos[idx].prot.indexOf("s") < 0) return bpriv.getString("unprotected"); else if(bpriv.lsos[idx].prot.indexOf("d") >= 0) return bpriv.getString("protectedFolder"); else if(bpriv.lsos[idx].prot.indexOf("s") >= 0) return bpriv.getString("protectedSubFolder"); } return ""; }, }, LSOTreeShow: function(flashDir) { var cDate = new Date(); if (!flashDir) { // Display error if selected directory does not exist bpriv.getDoc().getElementById("appdir").setAttribute ("readonly","true"); bpriv.getDoc().getElementById("appdir").value = bpriv.getString("dirNotFound"); bpriv.getDoc().getElementById("appdir").style.backgroundColor = "red"; bpriv.getDoc().getElementById("appdir").style.color = "white"; bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("searchFlashFolder"); bpriv.getDoc().getElementById("lsoinfo").value = ""; bpriv.getDoc().getElementById("tip").value = "Status " + cDate.toLocaleString(); } else { bpriv.getDoc().getElementById("appdir").removeAttribute("readonly"); bpriv.getDoc().getElementById("appdir").value = flashDir.path; bpriv.getDoc().getElementById("appdir").style.backgroundColor = ""; bpriv.getDoc().getElementById("appdir").style.color = ""; bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("searchFlashFolder"); bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("listLSOs"); bpriv.getDoc().getElementById("tip").value = "Status " + cDate.toLocaleString(); } setTimeout(function(){bpriv.LoadLsosIntoTree(flashDir);}, 500, flashDir); //provide time to update GUI }, LoadLsosIntoTree: function(flashDir) { bpriv.lsos = []; if (flashDir) bpriv.LoadLsos(flashDir, true); bpriv.updateGUI(flashDir, true); bpriv.TreeOnSelect(flashDir); }, ReloadLsos: function() { bpriv.LSOTreeShow(bpriv.GetFlashDir(0)); }, updateGUI: function(flashDir, sort) { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); if(!LSOTree) return; LSOTree.view = bpriv.treeView; bpriv.updateKnownLSOs(); bpriv.getDoc().getElementById("lso_removed").value = navigator.preference("extensions.bprivacy.removed"); bpriv.getDoc().getElementById("lso_removedSession").value = navigator.preference("extensions.bprivacy.removedSession"); bpriv.getDoc().getElementById("removeAllLsos").disabled = bpriv.lsos.length == 0; bpriv.getDoc().getElementById("lsoinfo").value = ""; if(sort) bpriv.SortLSOView(null); else LSOTree.treeBoxObject.invalidate(); }, TreeOnSelect: function(flashDir) { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); if(!LSOTree) return; LSOTree.view = bpriv.treeView; if (/*!bpriv.lsos.length ||*/ LSOTree.currentIndex < 0 || !bpriv.lsos[LSOTree.currentIndex]) { bpriv.getDoc().getElementById("FullPathID").value = bpriv.getString("nothingselected"); bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("protectDir"); bpriv.getDoc().getElementById("removeLso").disabled = true; bpriv.getDoc().getElementById("protectLsoDir").disabled = true; return; } //save selection bpriv.selected = bpriv.lsos[LSOTree.currentIndex].path; bpriv.getDoc().getElementById("removeLso").removeAttribute("disabled"); bpriv.getDoc().getElementById("protectLsoDir").removeAttribute("disabled"); bpriv.getDoc().getElementById("FullPathID").value = bpriv.lsos[LSOTree.currentIndex].path; if(bpriv.lsos[LSOTree.currentIndex].prot.indexOf("d") >= 0) bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("unprotectDir"); else bpriv.getDoc().getElementById("protectLsoDir").label = bpriv.getString("protectDir"); }, getLSOProtection: function(entry) { var exp = new RegExp(entry.leafName, 'i'); var dir = entry.path.replace(exp, ""); dir = dir.replace(/[\\\/]$/i, "").toLowerCase(); var prot = ""; var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|"); var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)', 'i'); if(navigator.preference("extensions.bprivacy.alwaysReScan")) dir = dir.replace(exp, ""); for (var x=0;x<protListarr.length;x++) { if(!String(protListarr[x]).length) continue; var protdir = protListarr[x].toLowerCase(); if(navigator.preference("extensions.bprivacy.alwaysReScan")) protdir = protdir.replace(exp, ""); if(dir == protdir){ prot = "d"; break; }else if(navigator.preference("extensions.bprivacy.autosubfolders") && dir.indexOf(protdir) >= 0){ prot = "s"; } } return prot; }, RefreshLSOProtection: function() { for (var i=0; i<bpriv.lsos.length; i++) bpriv.lsos[i].prot = bpriv.getLSOProtection(bpriv.lsos[i].file); }, LoadLsos: function(currentDir, doFootprint) { //bpriv.LOG("Checking folder for LSOs: " + currentDir.path); var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|"); var entries; try{ entries = currentDir.directoryEntries; }catch(e){} if(!entries) bpriv.LOG("BetterPrivacy Warning: A LSO folder is inaccessable: " + currentDir.path); while(entries && entries.hasMoreElements()) { try{ var entry = entries.getNext(); entry.QueryInterface(Components.interfaces.nsIFile); if (entry.isFile() && !entry.isSymlink() && !bpriv.isSpecial(entry)) { try{ if (bpriv.isLSO(entry, doFootprint)) { var cDate = new Date(); var ticks = cDate.getTime(); var modified = ticks-entry.lastModifiedTime; var prot = bpriv.getLSOProtection(entry); var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx"), 'i'); var ident = entry.path.replace(exp, ""); exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.DefaultLSORegEx"), 'i'); ident = String(ident).replace(exp, ""); ident = String(ident).match(/[^\\\/]+\.[^\\\/]+/, ""); ident = String(ident).replace(/^[#]/, ""); bpriv.lsos[bpriv.lsos.length] = new bpriv.Lso( entry, /*entry.parent.leafName*/ ident, entry.fileSize, entry.path, prot, String(ticks - modified)); } }catch(e){bpriv.LOG("BetterPrivacy: An error occured while scanning folders for LSO data" + e);} } else if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry)){ bpriv.LoadLsos(entry, doFootprint); } }catch(e){bpriv.LOG("BetterPrivacy: Error while scanning folders for LSO data" + e);} } protListarr = null; }, isLSO: function(item, doFootprint) { var str; var dotIndex = item.leafName.lastIndexOf('.'); var extension = (dotIndex >= 0) ? item.leafName.substring(dotIndex+1) : ""; if(extension.toLowerCase() != navigator.preference("extensions.bprivacy.LSOExtension").toLowerCase()) return false; if(doFootprint) { var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); try{ file.initWithPath(item.path); if (file.exists()) { var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream); try{ istream.init(file, -1, -1, false); bstream.setInputStream(istream); str = String(bstream.readBytes(bstream.available() > 4 ? 4 : bstream.available()));//only read needed bytes }catch(e){bpriv.LOG("BetterPrivacy: HexFootPrint error 1 " + e); return false;} bstream.close(); istream.close(); if(str && str.length >= 4) { var h = navigator.preference("extensions.bprivacy.LSOHexFootprint").split("|");//get hexfootprint for (var i = 0; i < 4; i++) { if(str.charCodeAt(i) != h[i]) //compare return false; } } } }catch(e){bpriv.LOG("BetterPrivacy: HexFootPrint error 2 " + e); return false;} } return true; }, Lso: function(entry, ident, size, path, prot, modified) { this.file = entry; this.ident = ident; this.name = entry.leafName; this.size = size; this.path = path; this.prot = prot; this.modified = modified; return this; }, FindLSORoot: function(HomeDir, ExToFind) { if(bpriv.Stack.length > 0) return; //important bpriv.Stack[0] = HomeDir; bpriv.Scan = 1; bpriv.FindLSORootNonRecursive( ExToFind, 1); }, FindLSORootNonRecursive: function(ExToFind, done) { var finish = function(newdir){ bpriv.LSOTreeShow(newdir); bpriv.Scan = 0; bpriv.Stack = []; } var currentDir = bpriv.Stack.pop(); if (ExToFind.test(currentDir.leafName)) { var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); try{ Dir.initWithPath(currentDir.path); if(Dir.path && Dir.exists() && Dir.isDirectory()) // navigator.preference("extensions.bprivacy.flashAppDir", Dir.path); // navigator.preference("extensions.bprivacy.DataDir", Dir); bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, Dir); else Dir = null; }catch(e){Dir = null;} finish(Dir); return; } done++; var entries; try{ entries = currentDir.directoryEntries; }catch(e){} while(entries && entries.hasMoreElements() && bpriv.Scan > 0) { var entry = entries.getNext(); entry.QueryInterface(Components.interfaces.nsIFile); if (entry.isDirectory() && !entry.isSymlink() && !bpriv.isSpecial(entry)) bpriv.Stack.push(entry); } if(bpriv.Scan > 0 && bpriv.Stack.length > 0){ //GUI if(bpriv.getDoc().getElementById("lsoinfo")) bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("LSOFolderScan") + " ["+done+"]"; if(bpriv.getDoc().getElementById("searchFolderID")) bpriv.getDoc().getElementById("searchFolderID").label = bpriv.getString("abort"); //GUI-end setTimeout( function(){bpriv.FindLSORootNonRecursive( ExToFind, done)}, 1, ExToFind, done); }else{ if(bpriv.Scan > 0 && bpriv.getDoc().getElementById("lsoinfo")) bpriv.getDoc().getElementById("lsoinfo").value = bpriv.getString("NoDirFound"); finish(bpriv.GetFlashDir(0)); } }, isSpecial: function(entry) { try{ return entry.isSpecial(); }catch(e){} return false; //no avail on Mac }, RemoveFromLSOProtection: function(path) { var exp = new RegExp('^.*'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)', 'i'); if(navigator.preference("extensions.bprivacy.alwaysReScan")) path = path.replace(exp, ""); var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|"); for (var x=0;x<protListarr.length;x++) { var dir = protListarr[x]; if(navigator.preference("extensions.bprivacy.alwaysReScan")) dir = dir.replace(exp, ""); if(dir.toLowerCase() == path.toLowerCase()) protListarr.splice(x, 1); } navigator.preference("extensions.bprivacy.protectedLSOList", protListarr.join("|")); protListarr = null; }, AddToLSOProtection: function(path) { var protListarr = navigator.preference("extensions.bprivacy.protectedLSOList").split("|"); for (var x=0;x<protListarr.length;x++) { if(protListarr[x].toLowerCase() == path.toLowerCase()){ protListarr = null; return; } } protListarr.push(path); navigator.preference("extensions.bprivacy.protectedLSOList", protListarr.join("|")); protListarr = null; }, ToggleLSOProtection: function(mode) { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); if(LSOTree.currentIndex < 0) return; var toModify = LSOTree.currentIndex; var path = bpriv.lsos[toModify].path; var exp = new RegExp(bpriv.lsos[toModify].file.leafName, 'i'); path = path.replace(exp, ""); path = path.replace(/[\\\/]$/i, ""); if(bpriv.lsos[toModify].prot.indexOf("d") < 0){ bpriv.AddToLSOProtection(path); bpriv.lsos[toModify].prot = "d"; }else { bpriv.RemoveFromLSOProtection(path); bpriv.lsos[toModify].prot = bpriv.lsos[toModify].prot.replace(/d/g, ""); } bpriv.RefreshLSOProtection(); bpriv.updateGUI(bpriv.GetFlashDir(0), false); bpriv.TreeOnSelect(); }, DeleteLso: function() { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); if(!bpriv.lsos[LSOTree.currentIndex]) return; try{ if(bpriv.lsos[LSOTree.currentIndex].file.exists()) bpriv.lsos[LSOTree.currentIndex].file.remove(false); else alert("This file does not exist anymore, nothing to do"); }catch(e){alert("Error: Failed to delete that file!"); return;} bpriv.lsos.splice(LSOTree.currentIndex , 1); LSOTree.treeBoxObject.rowCountChanged(LSOTree.currentIndex + 1 , -1); bpriv.updateGUI(bpriv.GetFlashDir(0), false); bpriv.TreeOnSelect(); bpriv.delDirs(bpriv.GetFlashDir(0)); }, DeleteAllLsos: function() { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); var protectedCookie = false; for (var x=0;x<bpriv.lsos.length;x++) { if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0){ protectedCookie = true; break; } } var button = 0; if(protectedCookie) { check = {value: false}; var flags = bpriv.prompts.BUTTON_POS_0 * bpriv.prompts.BUTTON_TITLE_YES + bpriv.prompts.BUTTON_POS_1 * bpriv.prompts.BUTTON_TITLE_NO + bpriv.prompts.BUTTON_POS_2 * bpriv.prompts.BUTTON_TITLE_CANCEL; button =bpriv.prompts.confirmEx(null, "BetterPrivacy", bpriv.getString("asktodeleteall"), flags, "", "", "", null, check); if(button == 2) return; } var deleted = 0; for (var x=0;x<bpriv.lsos.length;x++) { protectedCookie = false; if(String(bpriv.lsos[x].prot).indexOf("d") >= 0 || String(bpriv.lsos[x].prot).indexOf("s") >= 0) protectedCookie = true; try{ if(!(button == 1 && protectedCookie)){ bpriv.lsos[x].file.remove(false); deleted++; } }catch(e){} } if(deleted){ bpriv.LSOTreeShow(bpriv.GetFlashDir(0)); bpriv.TreeOnSelect(); bpriv.delDirs(bpriv.GetFlashDir(0)); } }, GetRootDir: function(platform) { switch (platform){ case "windows": return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("AppData", Components.interfaces.nsILocalFile)); break; case "mac1": return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ULibDir", Components.interfaces.nsILocalFile)); break; case "mac2": return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UsrPrfs", Components.interfaces.nsILocalFile)); break; case "linux": //gets user-directory return(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("Home", Components.interfaces.nsILocalFile)); break; } return null; }, GetFlashDir: function(ForceSearch) // detection of Flash Apps directory { //ForceSearch=0: Try current preference if available (user may have set directory manually) otherwise get predifined places //ForceSearch=1: Ignore current preference, get predefined places (e.g. portable mode) //ForceSearch=2: Ignore current preference, get predefined places and if this fails do a scan (e.g. search directory) var FlashDir = null; var knownDir = null; var ExToFind = new RegExp('^'+navigator.preference("extensions.bprivacy.FlashDirRegEx")+'(\u005c\u002f|\u005c\u005c)?$', 'i'); var Dir = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); if(ForceSearch < 1) { var currentDir; try{ currentDir = bpriv.prefs.getComplexValue("DataDir", Components.interfaces.nsILocalFile); }catch(e){} if (currentDir) { try{ if(currentDir.path && currentDir.exists() && currentDir.isDirectory()) knownDir = currentDir; }catch(e){} } } //scan if(ForceSearch > 0 && !knownDir) { try{ //windows if(bpriv.GetRootDir("windows") && bpriv.GetRootDir("windows").exists() && bpriv.GetRootDir("windows").isDirectory()) { FlashDir = bpriv.GetRootDir("windows"); FlashDir.append("Roaming"); FlashDir.append("Macromedia"); if(FlashDir.exists() && FlashDir.isDirectory()) knownDir = FlashDir; if(!knownDir) { FlashDir = bpriv.GetRootDir("windows"); FlashDir.append("Macromedia"); if(FlashDir.exists() && FlashDir.isDirectory()) knownDir = FlashDir; } if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2)) bpriv.FindLSORoot(bpriv.GetRootDir("windows"), ExToFind); } }catch(e){} } if(ForceSearch > 0 && !knownDir) { try{ //mac1 if(bpriv.GetRootDir("mac1") && bpriv.GetRootDir("mac1").exists() && bpriv.GetRootDir("mac1").isDirectory()) { FlashDir = bpriv.GetRootDir("mac1"); FlashDir.append("Preferences"); FlashDir.append("Macromedia"); if(FlashDir.exists() && FlashDir.isDirectory()) knownDir = FlashDir; if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2)) bpriv.FindLSORoot(bpriv.GetRootDir("mac1"), ExToFind); } }catch(e){} } if(ForceSearch > 0 && !knownDir) { try{ //mac2 if(bpriv.GetRootDir("mac2") && bpriv.GetRootDir("mac2").exists() && bpriv.GetRootDir("mac2").isDirectory()) { FlashDir = bpriv.GetRootDir("mac2"); FlashDir.append("Macromedia"); if(FlashDir.exists() && FlashDir.isDirectory()) knownDir = FlashDir; if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2)) bpriv.FindLSORoot(bpriv.GetRootDir("mac2"), ExToFind); } }catch(e){} } if(ForceSearch > 0 && !knownDir) { try{ //linux if(bpriv.GetRootDir("linux") && bpriv.GetRootDir("linux").exists() && bpriv.GetRootDir("linux").isDirectory()) { FlashDir = bpriv.GetRootDir("linux"); FlashDir.append(".macromedia"); if(FlashDir.exists() && FlashDir.isDirectory()) knownDir = FlashDir; if(!knownDir && (!navigator.preference("extensions.bprivacy.noAutoScan") || ForceSearch == 2)) bpriv.FindLSORoot(bpriv.GetRootDir("linux"), ExToFind); } }catch(e){} } try{ if(knownDir.path && knownDir.exists() && knownDir.isDirectory()) { bpriv.prefs.setComplexValue("DataDir", Components.interfaces.nsILocalFile, knownDir); return knownDir; } }catch(e){} return null; }, SortLSOView: function(col) { var LSOTree = bpriv.getDoc().getElementById("LSOViewerTree"); if(!LSOTree) return; bpriv.SortTable(col, bpriv.lsos, LSOTree); }, SortTable: function(column, table, tree) { var columnName = column; if(!column) { if(tree.getAttribute("sortResource")) columnName = tree.getAttribute("sortResource"); else return; } var order = tree.getAttribute("sortDirection") == "ascending" ? 1 : -1; //if it's already sorted by that column, reverse sort if (tree.getAttribute("sortResource") == column) order *= -1; columnSort = function compare(a, b) { if (bpriv.prepareForComparison(a[columnName]) > bpriv.prepareForComparison(b[columnName])) return 1 * order; if (bpriv.prepareForComparison(a[columnName]) < bpriv.prepareForComparison(b[columnName])) return -1 * order; return 0; } table.sort(columnSort); //setting these will make the sort option persist tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending"); tree.setAttribute("sortResource", columnName); tree.view = bpriv.treeView; //set the appropriate attributes to show to indicator var cols = tree.getElementsByTagName("treecol"); for (var i = 0; i < cols.length; i++) { cols[i].removeAttribute("sortDirection"); } bpriv.getDoc().getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending"); //redraw tree tree.treeBoxObject.invalidate(); //get old selection tree.view.selection.select(-1); if(bpriv.selected != null) { for (var i = 0; i < table.length; i++) { if (table[i].path == bpriv.selected) { tree.view.selection.select(i); //scroll into view tree.treeBoxObject.ensureRowIsVisible(i); break; } } } }, //prepares an object for easy comparison against another. for strings, lowercases them prepareForComparison: function(o) { if (typeof o == "string") return o.toLowerCase(); return o; }, showBetterPrivacy: function(){ var enumerator = bpriv.wm.getEnumerator(""); var win; while(enumerator && enumerator.hasMoreElements()) { awin = enumerator.getNext(); if(awin && awin.document && awin.document.getElementById("bprivprefpane")){ win = awin; break; } } if(!win) win = window.openDialog('chrome://bp/content/bp.xul', '_blank', 'chrome=yes, resizable=yes, centerscreen=yes', 1); win.focus(); }, getString: function(strID){ var str = ""; try{ str = bpriv.getDoc().getElementById("strBundle").getString(strID); }catch(e){} return str; }, hashString: function(str){ var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]. createInstance(Components.interfaces.nsIScriptableUnicodeConverter); // we use UTF-8 here, you can choose other encodings. converter.charset = "UTF-8"; // result is an out parameter, // result.value will contain the array length var result = {}; // data is an array of bytes var data = converter.convertToByteArray(str, result); var ch = Components.classes["@mozilla.org/security/hash;1"] .createInstance(Components.interfaces.nsICryptoHash); ch.init(ch.MD5); ch.update(data, data.length); var hash = ch.finish(false); // return the two-digit hexadecimal code for a byte function toHexString(charCode) { return ("0" + charCode.toString(16)).slice(-2); } // convert the binary hash data to a hex string. var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join(""); // s now contains your hash in hex: should be return s; }, onKeyCode: function() { bpriv.prepareDelLSO(0, null); }, addSanitizeItem: function () { if(!navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode")) return; if (typeof Sanitizer != 'function') return; // Sanitizer will execute this Sanitizer.prototype.items["extensions-betterprivacy"] = { clear : function(){ try{ bpriv.sanitize(window.document); }catch(e){} }, get canClear(){ return true; } } }, addSanitizeMenuItem: function () { if(!navigator.preference("extensions.bprivacy.AutoDelLSOnExitMode")) return; var prefs = document.getElementsByTagName("preferences")[0]; if(!prefs.hasChildNodes()) return; var id = prefs.lastChild.getAttribute("id"); if (prefs && id) { var prefName; if (id.indexOf("privacy.cpd.") != -1) { prefName = "privacy.cpd.extensions-betterprivacy"; var oldPrefName = "privacy.item.extensions-betterprivacy"; //if an old pref exists then use it if (!navigator.preference(prefName) && navigator.preference(oldPrefName)) navigator.preference(prefName, navigator.preference(oldPrefName)); } else if (id.indexOf("privacy.") != -1) { prefName = "privacy.item.extensions-betterprivacy"; } else return; var pref = document.createElement("preference"); pref.setAttribute("id", prefName); pref.setAttribute("name", prefName); pref.setAttribute("type", "bool"); prefs.appendChild(pref); var item; var itemList = document.getElementById("itemList"); if (itemList) item = itemList.lastChild; else { item = document.getElementsByTagName("checkbox"); item = item[item.length - 1]; } var check = document.createElement(itemList ? "listitem" : "checkbox"); check.setAttribute("label", "Flash Cookies"); check.setAttribute("preference", prefName); if(itemList) { check.setAttribute("type", "checkbox"); itemList.appendChild(check); } else { if(item.parentNode.childNodes.length == 2) { var row = document.createElement("row"); item.parentNode.parentNode.appendChild(row); row.insertBefore(check, null); }else item.parentNode.insertBefore(check, null); } if (typeof(gSanitizePromptDialog) == "object") { pref.setAttribute("readonly", "true"); check.setAttribute("onsyncfrompreference", "return gSanitizePromptDialog.onReadGeneric();"); } } }, sanitize: function (doc) { var ticks = 0; if(doc.getElementById("sanitizeDurationChoice")) { var idx = doc.getElementById("sanitizeDurationChoice").selectedIndex; var currentTime = new Date(); switch(idx) { case 0: //1 hour ticks = 3600000; break; case 1: //2 hours ticks = 7200000; break; case 2: //4 hours ticks = 14400000; break; case 3: //today ticks = (currentTime.getHours() * 60 * 60 * 1000) + (currentTime.getMinutes() * 60 * 1000) + (currentTime.getSeconds() * 1000); break; } } //clear LSO data bpriv.prepareDelLSO(0, ticks); }, extopened: function() { var isExtensionsWin = document.getElementById("extensionsStrings"); if (isExtensionsWin) //extensions manager { eval("gExtensionsViewController.commands.cmd_options ="+gExtensionsViewController.commands.cmd_options.toString().replace( 'var optionsURL = aSelectedItem.getAttribute("optionsURL");', '$& \ if (bpriv.isOptionsURL(optionsURL)) return;' )); } }, isOptionsURL: function(url) { if (url != "chrome://bp/content/bp.xul") return false; var gWindowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator); var aBrowser = gWindowManager.getMostRecentWindow("navigator:browser"); if (!aBrowser) { var rwin = gWindowManager.getMostRecentWindow("mozilla:betterprivacy"); if(rwin) rwin.close(); bpriv.prompts.alert(window, "BetterPrivacy", "BetterPrivacy requires at least one open browser window!"); } else bpriv.showBetterPrivacy(); return true; }, };